<template>
  <div>
    <template>
      <div>
        <el-table
          :data="list"
          style="width: 100%;margin-bottom: 20px;"
          row-key="id"
          border
          :tree-props="{children: 'children'}"
        >
          <el-table-column prop="id" label="编号" sortable width="180"></el-table-column>
          <el-table-column prop="title" label="轮播图标题" sortable width="180"></el-table-column>

          <el-table-column label="图片">
            <template slot-scope="scope">
              <img :src="$pre+scope.row.img" alt />
            </template>
          </el-table-column>

          <el-table-column label="状态">
            <template slot-scope="scope">
              <!-- scope里面包括这条数据  和下标 -->
              <el-button type="primary" v-if="scope.row.status===1">启用</el-button>
              <el-button type="info" v-else>禁用</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary" @click="willEdit(scope.row.id)">编辑</el-button>
              <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </template>
  </div>
</template>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { reqbannerdelete } from "../../../request/api";
import { successAlert } from "../../../utils/alert";
export default {
  props: ["user"],
  data() {
    return {
      // list: [],
    };
  },

  mounted() {
    // console.log(this.list);
    this.reqList();
  },
  computed: {
    ...mapGetters({
      list:'banner/list'
    }),
  },
  methods: {
    ...mapActions({
      reqList: "banner/reqList",
    }),
    willEdit(id) {
      this.$emit("willEdit", id);
    },
    del(id) {
      this.$confirm("是否删除?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          reqbannerdelete({
            id: id,
          }).then((res) => {
            if (res.data.code == 200) {
              this.reqList();
              successAlert(res.data.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang='less' scoped>
@import "../../../less/index.less";
img {
  width: 60px;
  height: 60px;
}
</style>